Skip to content

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Sep 2, 2025

Backport 63195d3 3e6ec47

Requested by: @amy-kwan

A CMake change included in CMake 4.0 makes `AIX` into a variable
(similar to `APPLE`, etc.)
https://gitlab.kitware.com/cmake/cmake/-/commit/ff03db6657c38c8cf992877ea66174c33d0bcb0b

However, `${CMAKE_SYSTEM_NAME}` unfortunately also expands exactly to
`AIX` and `if` auto-expands variable names in CMake. That means you get
a double expansion if you write:

`if (${CMAKE_SYSTEM_NAME}  MATCHES "AIX")`
which becomes:
`if (AIX  MATCHES "AIX")`
which is as if you wrote:
`if (ON MATCHES "AIX")`

You can prevent this by quoting the expansion of "${CMAKE_SYSTEM_NAME}",
due to policy
[CMP0054](https://cmake.org/cmake/help/latest/policy/CMP0054.html#policy:CMP0054)
which is on by default in 4.0+. Most of the LLVM CMake already does
this, but this PR fixes the remaining cases where we do not.

(cherry picked from commit 63195d3)
This is a follow on to llvm#154537, which quoted the CMAKE_SYSTEM_NAME to avoid expanding it again when that CMAKE_SYSTEM_NAME expands to AIX.

But by the same logic, we also need to quote the plain string AIX as well.

(cherry picked from commit 3e6ec47)
@llvmbot
Copy link
Member Author

llvmbot commented Sep 2, 2025

@hubert-reinterpretcast What do you think about merging this PR to the release branch?

@tru tru moved this from Needs Triage to Needs Review in LLVM Release Status Sep 3, 2025
Copy link
Collaborator

@hubert-reinterpretcast hubert-reinterpretcast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@github-project-automation github-project-automation bot moved this from Needs Review to Needs Merge in LLVM Release Status Sep 8, 2025
@tru
Copy link
Collaborator

tru commented Sep 9, 2025

Uhm - this looks pretty big and seems like something that can easily break certain build configurations since it doesn't seem to touch only AIX. Is this in main without any issues? Does it really NEED to be merged for the release branch at this point?

@daltenty
Copy link
Member

daltenty commented Sep 9, 2025

Uhm - this looks pretty big and seems like something that can easily break certain build configurations since it doesn't seem to touch only AIX

Agreed that this looks big and scary, but it's a purely mechanical change, that is a no-op for most targets. I'll add a long form rational at the end of the comment about why I don't think the patch effects anyone but AIX to keep my answers brief.

Is this in main without any issues?

Yes, these patches have been in main for several weeks at this point with no reported issues.

Does it really NEED to be merged for the release branch at this point?

It would help us out for the point releases. Without this patch, we're unable to build on AIX with CMake from our package manager (4.0). We can manually downgrade if we're unwilling to merge this, but it's a bit of a pain.

Rationale about why the patch doesn't affect targets besides AIX

We quote the string AIX and variable expansions which might expand to string AIX (i.e. CMAKE_SYSTEM_NAME), so that we do the intent string comparison. If not quoted the if will expand the string if it happens to match a variable name (which AIX does in CMake 4.0+).

This has an effect only if CMAKE_SYSTEM_NAME (https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html) expands to something which is a CMake variable (https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html#variables-that-describe-the-system)

Intersecting the two list gives me the following list of affect targets:

AIX
CYGWIN
MSYS
WASI

Of those targets, only CYGWIN appears in the lines affected by the patch, and it's already using a variable check (i.e. it checks CYGWIN) not a string comparison to CMAKE_SYSTEM_NAME, so it's unaffected.

@amy-kwan
Copy link
Contributor

Uhm - this looks pretty big and seems like something that can easily break certain build configurations since it doesn't seem to touch only AIX

Agreed that this looks big and scary, but it's a purely mechanical change, that is a no-op for most targets. I'll add a long form rational at the end of the comment about why I don't think the patch effects anyone but AIX to keep my answers brief.

Is this in main without any issues?

Yes, these patches have been in main for several weeks at this point with no reported issues.

Does it really NEED to be merged for the release branch at this point?

It would help us out for the point releases. Without this patch, we're unable to build on AIX with CMake from our package manager (4.0). We can manually downgrade if we're unwilling to merge this, but it's a bit of a pain.

Rationale about why the patch doesn't affect targets besides AIX

We quote the string AIX and variable expansions which might expand to string AIX (i.e. CMAKE_SYSTEM_NAME), so that we do the intent string comparison. If not quoted the if will expand the string if it happens to match a variable name (which AIX does in CMake 4.0+).

This has an effect only if CMAKE_SYSTEM_NAME (https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html) expands to something which is a CMake variable (https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html#variables-that-describe-the-system)

Intersecting the two list gives me the following list of affect targets:

AIX
CYGWIN
MSYS
WASI

Of those targets, only CYGWIN appears in the lines affected by the patch, and it's already using a variable check (i.e. it checks CYGWIN) not a string comparison to CMAKE_SYSTEM_NAME, so it's unaffected.

Hi @tru! Any thoughts regarding @daltenty's response on this backport?

@tstellar tstellar moved this from Needs Merge to Needs Review in LLVM Release Status Sep 22, 2025
@tru
Copy link
Collaborator

tru commented Sep 29, 2025

I still feel pretty sketchy about this one. It seems large and could affect other platforms than AIX since it's changing the build system in pretty large ways.

I would be much more comfortable if we just drop this for the release branch and make sure it's working well in main before the next release. The main problem I have here is that there is also no maintainer for the CMake scripts in whole, I guess maybe @petrhosek would be the closest.

I understand it could be a bit of a pain for the AIX packages - but I wonder if it's not worth a little pain for a platform that ... frankly isn't that mainstream in order to avoid any potential issues with other platforms. I understand that it's not a blocker really, just annoying so that gives me more confidence to reject this.

@c-rhodes c-rhodes moved this from Needs Review to Won't Merge in LLVM Release Status Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Won't Merge

Development

Successfully merging this pull request may close these issues.

5 participants